﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static System.Console;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            this.label1.Text = " ";
        }

        private int num1=0;
        private int num2=0;
        private int result=0;
        //private string temp;
        private char s=' ';

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.s = '+';
            this.num1 = Int32.Parse(this.label1.Text);
            this.label1.Text = " ";
        }


        private void button2_Click(object sender, EventArgs e)
        {
            this.s = '-';
            this.num1 = Int32.Parse(this.label1.Text);
            this.label1.Text = " ";
        }

        private void button3_Click(object sender, EventArgs e)
        {
            this.s = '*';
            this.num1 = Int32.Parse(this.label1.Text);
            this.label1.Text = " ";
        }

        private void button5_Click(object sender, EventArgs e)
        {
            this.s = '/';
            this.num1 = Int32.Parse(this.label1.Text);
            this.label1.Text =  " ";
        }





        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void button8_Click(object sender, EventArgs e)
        {if(this.label1.Text!="0")
            this.label1.Text= this.label1.Text + "0";
        }

        private void button7_Click(object sender, EventArgs e)
        {
            this.label1.Text = this.label1.Text + "1";
        }

        private void button6_Click(object sender, EventArgs e)
        {
            this.label1.Text = this.label1.Text + "2";
        }

        private void button4_Click(object sender, EventArgs e)
        {
            this.label1.Text = this.label1.Text + "3";
        }

        private void button12_Click(object sender, EventArgs e)
        {
            this.label1.Text = this.label1.Text + "4";
        }

        private void button11_Click(object sender, EventArgs e)
        {
            this.label1.Text = this.label1.Text + "5";
        }

        private void button10_Click(object sender, EventArgs e)
        {
            this.label1.Text = this.label1.Text + "6";
        }

        private void button9_Click(object sender, EventArgs e)
        {
            this.label1.Text = this.label1.Text + "7";
        }

        private void button16_Click(object sender, EventArgs e)
        {
            this.label1.Text = this.label1.Text + "8";
        }

        private void button15_Click(object sender, EventArgs e)
        {
            this.label1.Text = this.label1.Text + "9";
        }

        private void button14_Click(object sender, EventArgs e)
        {
            this.label1.Text = " ";
            this.textBox1.Text = " ";
            this.s = ' ';
            num1 = num2 = 0;
        }

        private void button13_Click_1(object sender, EventArgs e)
        {
            
            if (this.label1.Text == " ")
            { 
                this.textBox1.Text = "请输入操作数！！！";
                return;
            }

            else this.num2 = Int32.Parse(this.label1.Text);
            this.textBox1.Text = " ";
            switch (s)
            {
                case '+':
                    result = num1 + num2;
                    this.label1.Text = Convert.ToString(this.result);
                    break;
                case '-':
                    result = num1 - num2;
                    this.label1.Text = Convert.ToString(this.result);
                    break;
                case '*':
                    result = num1 * num2;
                    this.label1.Text = Convert.ToString(this.result);
                    break;
                case '/':
                    if (num2 == 0)
                    {
                        this.textBox1.Text = "除数不能为零！！！";
                        this.label1.Text = "ERRO";
                        return;
                    }
                    else result = num1 / num2;
                    this.label1.Text = Convert.ToString(this.result);
                    break;
                default:
                    this.textBox1.Text = "请选择运算符！！！";
                    break;
            }
            
        }
    }
}
